//
//    Copyright (C) 2012  OinkStudio
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package game;

import java.io.Serializable;

public abstract class Player implements Serializable {

	private Obolo[] deck;
	private int[] oboloDeckUsed;
	private String name;

	protected Player(String name) {
		this.name = name;		
	}

	public void setOboloUsed(Obolo obolo){
		
		int position = 0;
				
		while(position < deck.length && !obolo.equals(deck[position])){		
			if(deck[position] == null){
				oboloDeckUsed[position] = 1;
			}
			position++;
		}
		if(position < deck.length){
			oboloDeckUsed[position] = 1;			
		}		
	}
	
	public Obolo getObolo(int indexDeck) {
		Obolo obolo = deck[indexDeck];
		deck[indexDeck] = null;
		return obolo;
	}

	public void setDeck(Obolo[] deck) {
		this.deck = deck;
		oboloDeckUsed = new int[deck.length];
		for(int position = 0; position < deck.length; position++){
			oboloDeckUsed[position] = 0;
		}
	}

	public void setOwnerId(int ownerId) {
		for (Obolo obolo : deck) {
			if (obolo != null)
				obolo.setOwner(ownerId);
		}
	}

	public void removeOboloFromDeck(Obolo obolo) {
		for (int i = 0; i < deck.length; i++)
			if (deck[i] != null && deck[i].beEquals(obolo))
				deck[i] = null;
	}

	public Obolo[] getDeck() {
		return deck;
	}
	
	public String getName() {
		return name;
	}

	public int[] getUsedDeck(){
		return oboloDeckUsed;
	}
	public boolean isHuman() {
		return false;
	}

}
